package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketKeyword;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.admin.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author klw
 * @Data 2022/11/20 下午10:40
 */

@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @GetMapping("list")  //list 接口 列表
    public BaseRespVo<CommonData>list(String keyword, String url, BasePageInfo basePageInfo){
        CommonData<MarketKeyword> query = keywordService.query(keyword,url, basePageInfo);

        return BaseRespVo.ok(query);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody MarketKeyword marketKeyword){
        keywordService.delete(marketKeyword);

        return BaseRespVo.ok();
    }

    @PostMapping("create")
    public BaseRespVo create(@RequestBody MarketKeyword marketKeyword){
        MarketKeyword marketKeyword1 = keywordService.createKeyword(marketKeyword);

        if(null == marketKeyword1){
            return BaseRespVo.error(611,"关键字已有!");
        }
        return BaseRespVo.ok(marketKeyword1);
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody MarketKeyword marketKeyword){
        MarketKeyword marketKeyword1 = keywordService.updateKeyword(marketKeyword);

        return BaseRespVo.ok(marketKeyword1);
    }
}
